<%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2022/11/12
  Time: 18:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登记审核</title>
</head>
<body>
        <form id="warehousingexaminemodalform">
        <div class="modal-header">
            <input type="submit" class="btn btn-default" value="复核通过">
            <button class="close" data-dismiss="modal">退出</button>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-md-offset-5">
                    <h2><strong>入库登记</strong></h2>
                </div>
                <input type="hidden" id="warehousingmoalids1" name="id">
            </div>
            <br>
            <div class="row">
                <div class="col-md-6">
                    <table>
                        <tr>
                            <td>入库单编号:</td>
                            <td><input type="text" id="warehousinggatherIds1" name="gatherId"  readonly style="outline: none;border: none"></td>
                        </tr>
                        <tr></tr>
                        <tr>
                            <td>入库理由:</td>
                            <td><input type="text" id="warehousingreasonexacts1" readonly style="outline: none;border: none"></td>
                        </tr>
                    </table>
                </div>
                <div class="col-md-6">
                    <table>
                        <tr>
                            <td>入库详情理由:</td>
                            <td><input type="text" id="warehousingreasons1" readonly style="outline: none;border: none"></td>
                        </tr>
                    </table>
                </div>
            </div>
            <br><br>
            <div style="height:45%">
                <table class="table" id="warehouingmodaltabs1">

                </table>
            </div>
            <br>
            <div class="row">
                <div class="col-md-6">
                    <table>
                        <tr>
                            <td>已入库总件数:</td>
                            <td><input type="text" id="gatheredAmountSumsums1" name="gatheredAmountSum" readonly style="outline: none;border: none" ></td>
                        </tr>

                        <tr>
                            <td>应入库总件数:</td>
                            <td><input type="text" id="warehousingamountSums1" name="amountSum" readonly style="outline: none;border: none" ></td>
                        </tr>

                        <tr>
                            <td>应入库总成本:</td>
                            <td><input type="text" id="warehousingcostPriceSums1"  readonly style="outline:none;border:none;"></td>
                        </tr>
                        <tr>
                            <td>复核人:</td>
                            <td><input type="text" id="warehousingcostcheckers1" value="${username}" name="checker"  readonly style="outline:none;border:none;"></td>
                        </tr>
                    </table>
                </div>
                <div class="col-md-6">
                    <table>
                        <tr>
                            <td>登记人:</td>
                            <td><input type="text" name="register" id="warehousingregisters1" readonly style="outline: none;border: none;border-bottom:1px black dashed"></td>
                        </tr>

                        <tr>
                            <td><strong>登记时间:</strong></td>
                            <td><input type="text" readonly name="registerTime" id="warehousingregisterTimes1" style="outline: none;border: none"></td>
                        </tr>
                        <tr>
                            <td><strong>复核时间:</strong></td>
                            <td><input type="text" readonly name="checkTime" id="warehousingregicheckTimes1" style="outline: none;border: none"></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        </form>

        <script>
                $(function () {
                    //加载数据
                    $("#warehouingmodaltabs1").bootstrapTable({
                        contentType: "application/x-www-form-urlencoded", //如果用tomcat就要写这个
                        striped: true,//是否显示隔行变色
                        cache: false,//是否缓存
                        pagination: false,//是否显示分页
                        sortable: false,//是否显示排序
                        clickToSelect: true,//是否启用点击选中行
                        uniqueId:"id",//每一行的唯一标识，一般为主键列,
                        showRefresh: true,//是否显示刷新按钮
                        columns:[
                            {
                                field:"",
                                title:"序号",
                                formatter:function (value,row,index) {
                                    return Number(index)+1
                                }
                            },
                            {
                                field:"productId",
                                title:"产品编号"
                            },
                            {
                                field:"productName",
                                title:"产品名称",
                            },
                            {
                                field:"costPrice",
                                title:"单价",
                            },
                            {
                                field:"amount",
                                title:"应入库件数"
                            },
                            {
                                field:"warehousing",
                                title:"已入库件数"
                            },
                            {
                                field:"gatheredAmount",
                                title:"本次入库数量",
                            }
                        ]
                    })
                })
                //加载入库表  入库详情表数据
                $(function () {
                    var datetimestack;
                    //点击获取当前时间
                    $.get("queryCellByDate.action",function (data) {
                        datetimestack=data.datetime;
                    },"json")
                    //获取值
                    var gatherId='${param.gatherId}'
                    $.post("queryByGatherGatherdetailswarhousing.action",{"gatherId":gatherId},function (data) {
                        //赋值
                        //入库单编号
                        $("#warehousinggatherIds1").val(data.gatherId);
                        //入库理由
                        $("#warehousingreasonexacts1").val(data.reasonexact)
                        //入库详情理由
                        $("#warehousingreasons1").val(data.reason)
                        //应入库总件数
                        $("#warehousingamountSums1").val(data.amountSum)
                        //入库总成本
                        $("#warehousingcostPriceSums1").val(data.costPriceSum)
                        //登记人
                        $("#warehousingregisters1").val(data.register)
                        //登记时间
                        $("#warehousingregisterTimes1").val(data.registerTime)
                        //复核时间
                        $("#warehousingregicheckTimes1").val(datetimestack)
                        //id
                        $("#warehousingmoalids1").val(data.id)
                        $("#gatheredAmountSumsums1").val(data.gatheredAmountSum)
                        //入库明细表数据
                        console.log(data.gatherDetails)
                        var gatherDetailss=data.gatherDetails;
                        var arr=[];
                        for(var i=0;i<gatherDetailss.length;i++){
                            arr.push(gatherDetailss[i])
                        }
                        //添加到表格中
                        $("#warehouingmodaltabs1").bootstrapTable("append",arr);
                    },"json")
                })

            $("#warehousingexaminemodalform").validate({
                submitHandler:function () {
                    //修改 入库表 和 入库明细表状态
                    var arr=$("#warehousingexaminemodalform").serializeArray();
                    //创建数组
                    var gather={}
                    $(arr).each(function (index,item) {
                        gather[item.name]=item.value;
                    })
                    //获取表格的数据
                    var arr1=$("#warehouingmodaltabs1").bootstrapTable("getData");
                    gather["gatherDetails"]=arr1;
                    console.log(gather)
                    $.ajax({
                        url:"updatewarehousingexaminequeryByGather.action",
                        data:JSON.stringify(gather),
                        contentType:"application/json",
                        type:"post",
                        dataType:"json",
                        success:function (data) {
                            alert(data.msg)
                            //关闭模态框
                            $("#warehousingexaminemodal").modal("hide")
                            //刷新表格
                            $("#warehousingexaminetab").bootstrapTable("refresh")
                        }
                    })
                }
            })
        </script>
</body>
</html>
